<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('上传附件')" />
    <!--<th:block th:include="include :: datetimepicker-css" />-->
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-attachment-add" enctype="multipart/form-data">
            <div class="form-group">
                <label class="col-sm-3 control-label text-red">主表id：</label>
                <div class="col-sm-8">
                    <input id="mainId" name="mainId" class="form-control" type="text" th:value="${mainId}" readonly required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label text-red">实体类名：</label>
                <div class="col-sm-8">
                    <input id="entityName" name="entityName" class="form-control" type="text" th:value="${entityName}" readonly required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label text-red">附件：</label>
                <div class="col-sm-8">
                    <input type="file" id="file" name="file" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea id="remark" name="remark" class="form-control" rows="3" maxlength="500"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <!--<th:block th:include="include :: datetimepicker-js" />-->
    <script type="text/javascript">
        var prefix = ctx + "system/attachment";

        $("#form-attachment-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                /*$.operate.save(prefix + "/add", $('#form-attachment-add').serialize());*/
                addAttachment();
            }
        }

        function addAttachment() {
            var formData = new FormData();
            formData.append("file", $('#file')[0].files[0]);
            formData.append("mainId", $("#mainId").val());
            formData.append("entityName", $("#entityName").val());
            formData.append("remark", $("#remark").val());
            $.ajax({
                url: prefix + "/add",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                type: 'POST',
                beforeSend: function () {
                    $.modal.loading("正在处理中，请稍后...");
                    $.modal.disable();
                },
                success: function (result) {
                    $.operate.successCallback(result);
                }
            });
        }

        /*$("input[name='uploadDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });*/
    </script>
</body>
</html>